package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import service.CartService;
import service.impl.CartServiceImpl;

/**
 * Servlet implementation class UpdateCartServlet
 */
public class UpdateCartServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    CartService cartServiceImpl = new CartServiceImpl(); 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateCartServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
    	response.setHeader("content-type","text/html;charset=UTF-8");
    	PrintWriter printWriter = response.getWriter();
    	String cdId = request.getParameter("cdId");
    	int num = Integer.parseInt(request.getParameter("dNum"));
    	int m = cartServiceImpl.updateCart(cdId, num);
    	System.out.println(m);
    	if(m>0){
    		printWriter.println("更新成功");
    	}else{
    		printWriter.println("更新不成功");
    	}
    	
	}

}
